<?php
namespace app\modules\adminapi\controllers;

use fate\http\Request;
use app\models\UserCreditLog;

class ListusercreditlogController extends \app\modules\adminapi\ForceLoginPure {

    public function run() {
        $req = Request::getInstance();

        $p = $req->getQueryString('page');
        $uid = $req->getQueryString('uid');
        $pageSize = 10;
        if(!is_numeric($p)) {
            $p = 1;
        }
        if(!is_numeric($uid)) {
            $uid = '';
        }

        // user center req
        $where = '1=1';

        if($uid) {
            $where = 'uid=' . $uid;
        }

        $credit = new UserCreditLog();
        $total = $credit->count($where);
        $ret = $credit->getListByPage(
            'id,uid,money,score,experience,action,log_time,reason',
            $where, $p, $pageSize);

        if(null !== $ret) {
            foreach($ret as $k => $val) {
                $ret[$k]['action_text'] = UserCreditLog::getActionName(intval($val['action']));
            }
        }

        $this->ajaxReturn([
            'page_size' => $pageSize,
            'current' => $p,
            'total' => $total,
            'data' => $ret
        ]);
    }

}
